<!DOCTYPE html>
<html lang="zn-CN">
<head>
    <meta charset="UTF-8">
    <title>BlasterWarning</title>
    <link rel="stylesheet" href="static/layui/css/layui.css">
    <script src="static/layui/layui.js"></script>
</head>
<body>

<div class="layui-bg-green" align="center">
    冲击波
</div>

<div class="layui-card">
    <div class="layui-card-body">
        <table id="blasterTable" lay-filter="blasterWaveTable"></table>
    </div>
</div>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-anim layui-anim-scaleSpring" lay-event="del">删除</a>
</script>

<script type="text/javascript">
    layui.use(['table', 'jquery','form', 'layer','upload'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;
        var upload = layui.upload;
        table.render({
            elem: '#blasterTable'
            , url: '/ip/listBlaster'
            , title: '冲击波监控'
            , totalRow: true
            , cols: [[  //表头
                {field: 'ipv4_SRC_ADDR', title: '源IP'},
                {field: 'ipv4_DST_ADDR', title: '目的IP'},
                {field: 'protocol', title: '协议号'},
                {field: 'l4_DST_PORT', title: '目的端口'},
                {field: 'in_PKTS', title: 'pkts'},
                {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
            ]],
            parseData: function (res) {
                console.log(res);
                if (res.data.length == 0) {
                    layer.msg("本地电脑暂时未监测到冲击波病毒！");
                }
                return {
                    "code": 0,
                    "msg": res.msg,
                    "count": res.data.length,
                    "data": res.data
                }
            },
        });


        table.on('tool(blasterTable)', function (obj) {
            var data = obj.data;    //获得当前行数据
            var layEvent = obj.event;   //获得 lay-event 对应的值（也可以是表头的event 参数对应的值）
            var tr = obj.tr;    //获得当前行 tr 的 DOM 对象（如果有的话）
            var ip = data.ipv4_SRC_ADDR;

            console.log(data);
            console.log(tr);
            var deptId = data.id;
            if (layEvent == 'del') {
                $.ajax({
                    url: '/ip/delete',
                    type: 'post',
                    data: {"ip": ip},
                    dataType: "json",
                    success: function (res) {
                        layer.msg(res.msg);
                        if (res.success) {
                            $(tr).remove();
                        }
                    },
                    error: function () {
                        layer.msg("请求失败！")
                    }
                })
            }
        })

    })
</script>

</body>
</html>